<?php
/**
 * Created by PhpStorm.
 * User: taotao
 * Date: 2019/9/23
 * Time: 11:13
 */

namespace App\Http\Controllers\WebApi\UserCenter;

use App\Http\Controllers\WebApi\BaseController;
use App\Http\Service\ZhaoPinService;
use Illuminate\Http\Request;

/**
 * 招聘相关
 * Class ZhaoPinController
 * @package App\Http\Controllers\WebApi\UserCenter
 */

class ZhaoPinController extends BaseController
{
    public $service = '';

    public function __construct()
    {
        parent::__construct();
        $this->service = new ZhaoPinService();
    }
/**zwp
 * 获取招聘总数和分页数
 * @param Request $request
 * @return array
 */
    public function getAllCount(Request $request){
        $uid = $request->uid;
        //$uid = 2;
        $pageSize = $request->pageSize?$request->pageSize:10;
        //$pageSize = 10;
        $data = $this->service->getAllCount($uid,$pageSize);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    /**zwp
     * 获取招聘列表
     * @param Request $request
     * @return array
     */
    public function getZhaoPinLists(Request $request){
        $uid = $request->get('loginUid');
        //$uid = 2;
        $page = $request->input('page',1);
        $pageSize = $request->input('pagesize',10);
        $data = $this->service->getZhaoPinLists($uid,$page,$pageSize);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }

    /**zwp
     * 招聘详情
     * @param Request $request
     * @return array
     */
    public function getZhaoPinDetail(Request $request){
        $id = $request->id;
        //$id = 38;
        $data = $this->service->getZhaoPinDetail($id);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    public function publishZhaoPin(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        $flag = $this->service->publishZhaoPin($uid,$data);
        if(!$flag){
            return $this->toJson(-100);
        }
        return $this->success();
    }

    /**
     * 用户投递列表
     * @param Request $request
     */
    public function acceptLists(Request $request)
    {
        $uid = $request->get('loginUid');
        //$uid = 2;
        $page = $request->input('page',1);
        $pageSize = $request->input('pagesize',20);

        return $this->success($this->service->getUserJobs($uid,$page,$pageSize));
    }

    /**
     * 岗位应聘详情
     * @param Request $request
     */
    public function acceptDetail(Request $request)
    {
        $id = $request->get('id');
        return $this->success($this->service->getJobsDetail($id));
    }

}